package com.share.demo.thread;

/**
 * created by caifan 2017/11/29
 */
public class Syn01 implements Runnable {
    static volatile int i = 0;

    @Override
    public void run() {
        for (int j = 0; j < 10000; j++) {
            synchronized (Syn01.class) {
                i++;
            }

        }
    }

    public static void main(String[] args) throws InterruptedException {
        /*Syn01 sync01 = new Syn01();
        Syn01 sync02 = new Syn01();
        Thread thread1 = new Thread(sync01);
        Thread thread2 = new Thread(sync02);
        thread1.start();
        thread2.start();*/
        Syn01 sync01 = new Syn01();
        Syn01 sync02 = new Syn01();
        Thread thread1 = new Thread(sync01);
        Thread thread2 = new Thread(sync02);
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
//        Thread.sleep(1000);
        System.out.println(i);


    }
}
